package com.jservice.api.service.upp;

import com.alibaba.fastjson.JSONObject;
import com.jservice.api.MsgCode;
import com.jservice.api.UppClient;
import com.jservice.api.dto.Request;
import com.jservice.api.dto.Response;
import com.jservice.api.dto.ResponseHeader;
import com.jservice.api.service.BaseService;
import com.jservice.api.service.IService;
import com.wondersgroup.upp.api.core.UPPlatformRequest;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 钱包余额查询
 * Created by YCJ on 2017/8/4.
 */
@Service("upp2034")
public class Upp2034 extends BaseService implements IService {

    private String SERVER_NAME = "upp.trade.balance.query";

    @Override
    public Response excute(Request request, Response response, ResponseHeader header, String method) throws Exception {
        Map paramMap = request.getData();
        String card_no = paramsStringFilter(paramMap.get("card_no"));

        Map data = new HashMap();
        if (card_no == null || card_no.length() == 0) {
            return renderFAIL(MsgCode.Code_1001, response, header);
        } else {
            data.put("card_no", card_no);
            data.put("trans_code", "020002");
            data.put("account_type", "01");
        }
        UPPlatformRequest uRequest = getUPRequest(SERVER_NAME, request.getHeader());
        uRequest.setBiz_content(sortParam(data));
        UppClient client = UppClient.getInstance();
        JSONObject jsonObject = client.doRequest(uRequest);
        if ("000000".equals(jsonObject.getString("code"))) {
            jsonObject.remove("code");
            return renderSUC(jsonObject, response, header);
        } else {
            return renderFAIL(MsgCode.Code_1009, "市民卡网关返回异常:" + jsonObject.getString("msg"), response, header);
        }
    }
}
